<?php

class Quantri_DonvitinhController extends Zend_Controller_Action
{

    public function init()
    {
        $option=array(
        		"layout" => "layout",
        		"layoutPath" => APPLICATION_PATH."/layouts/scripts/quantri"
        );
        Zend_Layout::startMvc($option);
        
        $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    }

    public function indexAction()
    {
        $Donvitinh = new Quantri_Model_DonViTinh();
        $rsDonvitinh = $Donvitinh->GetAll();
         
        $this->view->rsDonvitinh = $rsDonvitinh->toArray();
    }

    public function saveAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        $donvitinh = new Quantri_Model_DonViTinh();
        
        $Id = $this->_request->getParam("idDonvitinh","-1");
        $ten = $this->_request->getParam("ten","");       
        $trangthai = $this->_request->getParam("trangthai","");
        
        $donvitinh->Id=$Id;
        $donvitinh->Ten = $ten;        
        $donvitinh->TrangThai = $trangthai;
        
        $donvitinh->save();
    }
    public function xoaAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$donvitinh = new Quantri_Model_DonViTinh();
    	$id = $this->_request->getParam("id", "-1");
    
    	$donvitinh->Xoa($id);
    }
    public function suaAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$idDonvitinh = $this->_request->getParam("id","-1");
    
    	$donvitinh = new Quantri_Model_DonViTinh();
    	$donvitinh->Id = $idDonvitinh;
    
    	$rsDonvitinh = $donvitinh->GetById();
    	
    	echo json_encode($rsDonvitinh);
    }

}



